<?php 
/* Copyright 2006 Sxip Identity */
if (!defined('WHOBAR')) die("Please do not access directly");

function whobar_get_config($name) {
    global $config;
    return isset($config[$name]) ? $config[$name] : null;
}

function whobar_get_script($query='') {
    return whobar_get_config('script_url') . (strpos(whobar_get_config('script_url'), "?") !== false ? "&" : "?") . $query;
}

function whobar_get_session_request() {
    if (isset($_SESSION) and isset($_SESSION['whobar_request'])) {
        return $_SESSION['whobar_request'];
    }
    else {
        return array();
    }
}

function whobar_set_session_request($request) {
    $_SESSION['whobar_request'] = $request;
}

function whobar_proxy_to_site ($postvars) {
    $postvars = array_merge($postvars, whobar_get_passthru_from_request(whobar_get_session_request()));
    $postvars['whobar_signature'] = whobar_make_signature($postvars, whobar_get_config('secret'));
    ?>
<html>
<head>
<title>One moment please...</title>
<script type="text/javascript">
    function autoSubmit() {
        document.getElementById("whobarForm").submit();
    }
 </script>
</head>
<body onload="autoSubmit()">
    <form action="<?php echo whobar_get_config('handler_url'); ?>" id="whobarForm" method="post">
    <?php
        foreach ($postvars as $k => $v) {
            ?>
        <input type="hidden" name="<?php echo htmlentities($k); ?>" value="<?php echo htmlentities($v) ?>" />
            <?php
        }
    ?>
    <noscript>
        <input type="submit" value="Continue" />
        Click the button to continue.  You are only seeing this because you appear to have JavaScript disabled.
    </noscript>
    </form>
</body>
</html>
    <?php
        exit(0);
}

?>
